import 'package:mvvm_provider/base/base_state.dart';
import 'package:mvvm_provider/page/mine/data/model/info_model.dart';
import 'package:mvvm_provider/page/mine/data/repository/mine_repository.dart';
import 'package:mvvm_provider/page/novel/states/novel_state.dart';
import '../../../base/base_view_model.dart';
import '../../../config/handle_state.dart';
import '../../../model/response_model.dart';

class NovelViewModel extends BaseViewModel<NovelState> {
  NovelViewModel() : super(NovelState());

  /// 获取数据
  Future<void> getListData() async {
    ResponseModel? responseModel = await MineRepository.getInfoListData<InfoListModel>(1);

    /// 处理页面状态
    state.netState = HandleState.handle(responseModel);
    if (state.netState == NetState.dataSuccessState) {
      /// 数据请求成功
      InfoListModel infoListModel = responseModel.data;
      state.dataList = infoListModel.works;
    }
    notifyListeners();
  }

  /// 删除数据操作
  void removeData(int index) {
    if (index >= state.dataList.length) return;
    state.dataList.removeAt(index);
    notifyListeners();
  }
}
